package thunderbirdgtd.tests;

import static org.junit.Assert.*;

import java.awt.Color;
import java.util.LinkedList;

import org.junit.Test;

import thunderbirdgtd.entities.Priority;
import thunderbirdgtd.entities.Tag;

public class TagTest {
	
	@Test
	public void testTagLoadIds(){
		Tag o = new Tag("test", new Color(0), 5);
		Tag p = new Tag("test", new Color(0), 2);
		Tag n =new Tag("test2");
		
		assertEquals(6, n.getTagId());
	}

	@Test
	public void testTagStringColor() {
		Tag o= new Tag("test", new Color(0));
		Tag n=new Tag("test2");
		assertEquals("test", o.getTagName());
		assertEquals(new Color(0).getRed(), o.getColor().getRed());
		assertEquals("test2", n.getTagName());
	}

	@Test
	public void testTagString() {
		Tag o= new Tag("test", new Color(0));
		o.setTagName("new name");
		assertEquals("new name", o.getTagName());
		
	}
	
	@Test
	public void testTagIdSequence() {
		Tag o = new Tag("test");
		Tag p = new Tag("test2", new Color(0));
		assertEquals(1, (p.getTagId()-o.getTagId()));
	}


	@Test
	public void testTagDescription() {
		Tag o= new Tag("test", new Color(0));
		o.setTagDescription("new name");
		assertEquals("new name", o.getTagDescription());
	}


	@Test
	public void testColor() {
		Tag o= new Tag("test", new Color(0));
		o.setColor(new Color(1,2,3));
		assertEquals(1, o.getColor().getRed());
		assertEquals(2, o.getColor().getGreen());
		assertEquals(3, o.getColor().getBlue());
		
	}

	@Test
	public void testHasColor() {
		Tag o= new Tag("test", new Color(1,2,3));
		assertTrue(o.hasColor());
	}
	
	@Test
	public void testSearch() {
		
		LinkedList<Tag> ll=new LinkedList<Tag>();
		ll.add(new Tag("test"));
		ll.add(new Tag("test1"));
		ll.add(new Tag("test2"));
		Tag o=new Tag("test_that_passes");
		ll.add(o);
		
		try {
			assertEquals(o,Tag.searchTagInLinkedList("test_that_passes",ll));
			assertEquals(null,Tag.searchTagInLinkedList("wqertyu",ll));
		} catch (Exception e) {
			fail("failed");
		}
		
		try {
			Tag.searchTagInLinkedList(null,null);
			fail("test not passed"); 
		} catch (Exception e) {
			//all fine
		}
		
	}
	

}
